package zhaomh.catgirl.commands;

import org.bukkit.Material;
import org.bukkit.command.*;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import zhaomh.catgirl.zNeko;
import zhaomh.catgirl.zTools;
import zhaomh.catgirl.zConfig;

import java.util.ArrayList;
import java.util.List;

public class OwnerCommand implements CommandExecutor, TabExecutor {

    zTools t = new zTools("&d[Z-ねこむすめ]", null);

    public void helpCommand() {
        List<String> list = zConfig.getLanguageList("command.owner.help");
        for (String s : list) {
            t.sendM(s);
        }
    }
    @Override
    public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
        if (sender instanceof ConsoleCommandSender) {
            sender.sendMessage(zConfig.getLanguage("command.only-player"));
            return true;
        }

        t.setPlayer((Player) sender);

        if (zNeko.isOwner(t.getPlayer())) {
            t.sendM2(zConfig.getLanguage("command.owner.no"));
            return true;
        }

        if (args.length == 0) {
            helpCommand();
        } else if (args.length == 1) {
            if (args[0].equals("help")) {
                helpCommand();
            } else if (args[0].equals("item")) {
                ItemStack item = new ItemStack(Material.STICK);
                ItemMeta meta = item.getItemMeta();
                meta.setDisplayName(t.colorReplace(zConfig.getLanguage("item.stick")));
                meta.addEnchant(Enchantment.ARROW_DAMAGE,1,false);
                meta.addItemFlags(ItemFlag.HIDE_ENCHANTS);
                item.setItemMeta(meta);

                t.getPlayer().getInventory().addItem(item);
                t.sendM2(zConfig.getLanguage("command.owner.item.stick"));

            }
        }





        return true;
    }

    @Override
    public List<String> onTabComplete(CommandSender sender, Command command, String label, String[] args) {
        List<String> l = new ArrayList<>();

        if (args.length == 1) {
            l.add("help");
            l.add("item");
        }

        return l;
    }
}
